package com.yswy.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yswy.domain.vo.dto.TgDeviceHd;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.zip.CRC32;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("推广回传记录表")
@TableName(value = "tg_call_back_hd_id")
public class TgCallBackHdId {
    @TableId(type = IdType.AUTO)
    private Long id;
    @ApiModelProperty("用户Id")
    private Long userId;
    @ApiModelProperty("回调type")
    private Integer activeType;
    @ApiModelProperty("渠道")
    private String channle;
    @ApiModelProperty("一些跟广告信息相关的回调参数，内容是一个加密字符串，在调用事件回传接口的时候会用到")
    private String callbackparam;
    @ApiModelProperty("一些跟广告信息相关的回调参数，内容是一个加密字符串，在调用事件回传接口的时候会用到")
    private Long callbackparamCrc;
    @ApiModelProperty("ip")
    private String channelIp;
    @ApiModelProperty("uaStr")
    private String uaStr;
    @ApiModelProperty("加密imei，原值MD5 32位")
    private String imeiMd5;
    @ApiModelProperty("加密idfa，原值MD5 32位")
    private String idfaMd5;
    @ApiModelProperty("加密oaid，原值MD5 32位")
    private String oaidMd5;
    @ApiModelProperty("deviceMd5")
    private String deviceMd5;


    @ApiModelProperty("创建时间")
    private Date createTime;
    @ApiModelProperty("回传类型  0 付费  1 广告ecpm")
    private Integer isCallbackType;
    @ApiModelProperty("是否回调登录 0 未回传  1 回传  2扣量")
    private Integer isCallbackLogin;
    @ApiModelProperty("是否回调支付  0 未回传  1 回传  2扣量")
    private Integer isCallbackPay;

    public TgCallBackHdId(String channle , TgDeviceHd tgDeviceHd , Integer activeType , Integer isCallbackType ) {
        this.channle = channle;
        this.activeType = activeType;
        this.callbackparam = tgDeviceHd.getA_oId();
        CRC32 crc32 = new CRC32();
        crc32.update(tgDeviceHd.getA_oId().getBytes());
        this.callbackparamCrc = crc32.getValue();
        this.channelIp = tgDeviceHd.getIp();
        this.uaStr = tgDeviceHd.getUa();
        this.imeiMd5= tgDeviceHd.getImeiMd5();
        this.idfaMd5= tgDeviceHd.getIdfaMd5();
        this.oaidMd5= tgDeviceHd.getOaidMd5();
        this.deviceMd5= tgDeviceHd.getDeviceMd5();
        this.createTime = new Date();
        this.isCallbackType = isCallbackType;
        this.isCallbackLogin=0;
        this.isCallbackPay=0;
    }


    public static void main(String[] args) {
        CRC32 crc32 = new CRC32();
        crc32.update("c.rqB7I6enkYhGUseoWmFQtifecPLHpOOe7BRx0jOyNqXj7D16SjahWOiMzZsC7rKngpJJeoTQt3JZeLYf9ejgDqesRTRqR34memQ4RNFfa7TnkfPfXffyj1nypdVoSA7Yoms12ZPVyWM8J8HKDLuYgtJE".getBytes());
        System.out.println(crc32.getValue());
    }

}
